#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005],ans,c[200005];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",a+i);
        for(int i=0;i<(1<<n);i++){
                int res=0;
            for(int j=1;j<=n;j++)
                if(i&(1<<(j-1)))
                    c[j]=1;
                else
                    c[j]=0;
            int lsh=0,lsl=0;
            for(int j=1;j<=n;j++){
                if(c[j]==1){
                    if(a[j]==a[lsh])
                        res+=a[j];
                    lsh=j;
                }else{
                    if(a[j]==a[lsl])
                        res+=a[j];
                    lsl=j;
                }
            }
            ans=max(ans,res);
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005],t1[200005],p1[200005],p2[200005],t2[200005];
long long sum[200005],m1[200005],m2[200005];
long long solve(int l,int r){
    if(l==r)
        return 0;
    int mid=l+r>>1;
    long long res=solve(l,mid)+solve(mid+1,r);
    for(int i=mid+1;i<=r;i++){
        if(p1[i]<l||p1[i]>mid)
            continue;
        long long tmp=a[i]+sum[i-1]-sum[p1[i]],tmp1=0,tmp2=0,tmp3=a[i]+sum[i-1]-sum[p1[i]],tmp4=0;
        if(p1[i]!=l)
            tmp+=m1[p1[i]-1];
        if(i!=p1[i]+1&&a[p1[i]]!=a[p1[i]+1]&&a[p1[i]+1]==a[p1[i]-1])
            tmp1+=a[p1[i]+1];
        if(a[p1[i]]==a[p1[i]-1])
            tmp2+=a[p1[i]],tmp4+=a[p1[i]];
        if(a[p1[i]]==a[p1[i]-1]&&a[p1[i]+1]!=a[p1[i]]){
            if(p1[p1[i]+1]>=l){
                tmp3+=a[p1[i]+1];
                if(p1[p1[i]+1]!=p1[i]-1)
                    tmp3+=sum[p1[i]-1]-sum[p1[p1[i]+1]+1];
                if(p1[p1[i]+1]>l)
                    tmp3+=m1[p1[p1[i]+1]-1];
            }
        }
        if(i!=r)
            tmp+=m2[i+1];
        if(i!=p1[i]+1&&a[i]!=a[i-1]&&a[i-1]==a[i+1])
            tmp1+=a[i+1];
        if(a[i]==a[i+1])
            tmp2+=a[i+1],tmp4+=a[i+1];
        if(a[i]==a[i+1]&&a[i-1]!=a[i]){
            if(p2[i-1]<=r){
                tmp3+=a[p2[i-1]];
                if(p2[i-1]!=i+1)
                    tmp3+=sum[p2[i-1]-1]-sum[i+1];
                if(p2[i-1]<r)
                    tmp3+=m2[p2[i-1]+1];
            }
        }
        cout<<i<<' '<<tmp<<' '<<tmp1<<' '<<tmp2<<endl;
        res=max({res,tmp+max(tmp1,tmp2),tmp3+tmp4});
    }
    m1[l]=m2[r]=0;
    if(a[l]==a[l-1])
        m1[l]=a[l];
    if(a[r+1]==a[r])
        m2[r]=a[r+1];
    for(int i=l;i<=r;i++){
        if(p1[i]<l){
            m1[i]=m1[i-1];
            continue;
        }
        long long tmp=a[i]+sum[i-1]-sum[p1[i]],tmp1=0,tmp2=0;
        if(p1[i]!=l)
            tmp+=m1[p1[i]-1];
        if(i!=p1[i]+1&&a[p1[i]+1]==a[p1[i]-1])
            tmp1+=a[p1[i]+1];
        if(a[p1[i]]==a[p1[i]-1])
            tmp2+=a[p1[i]];
        m1[i]=max(m1[i-1],tmp+max(tmp1,tmp2));
    }
    for(int i=r;i>=l;i--){
        if(p2[i]>r){
            m2[i]=m2[i+1];
            continue;
        }
        long long tmp=a[p2[i]]+sum[p2[i]-1]-sum[i],tmp1=0,tmp2=0;
        if(i!=r)
            tmp+=m2[p2[i]+1];
        if(p2[i]!=i+1&&a[p2[i]-1]==a[p2[i]+1])
            tmp1+=a[p2[i]+1];
        if(a[p2[i]]==a[p2[i]+1])
            tmp2+=a[p2[i]+1];
        m2[i]=max(m2[i+1],tmp+max(tmp1,tmp2));
    }
    cout<<l<<' '<<r<<' '<<res<<endl;
    for(int i=l;i<=r;i++)
        cout<<m1[i]<<' ';
    cout<<endl;
    for(int i=r;i>=l;i--)
        cout<<m2[i]<<' ';
    cout<<endl;
    return res;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        for(int i=1;i<=n;i++)
            t1[i]=p1[i]=p2[i]=t2[i]=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",a+i);
            p1[i]=t1[a[i]];
            t1[a[i]]=i;
            sum[i]=sum[i-1];
            if(a[i]==a[i-1])
                sum[i]+=a[i];
        }
        for(int i=n;i>=1;i--){
            if(t2[a[i]]==0)
                p2[i]=n+1;
            else
                p2[i]=t2[a[i]];
            t2[a[i]]=i;
        }
        printf("%lld\n",solve(1,n));
    }
    return 0;
}
*/
